<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
$_SESSION['msort']=array();
$_SESSION['msort']['carnumber']=1;
$_SESSION['msort']['datetime']=1;
$_SESSION['msort']['name']=1;
$_SESSION['msort']['id']=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../jquery-1.8.2.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script>
function sordiem(ten){
	$.ajax({url:"aj_sort.php",data:{ten:ten},success:function(rslbk2){
		$("#show").html(rslbk2);
	}});
}
</script>
</head>
<?php 
include 'sorclass.php';
$connection1 = mysql_connect("1.234.20.151", "cam", "5678" ) ;
mysql_select_db("elicam", $connection1);
mysql_query("set names 'utf8'");
$sql="select t.id,c.name,t.car_datetime,t.carnumber,c.host,t.filename,t.isReg 
from carnum t ,configcamera c 
where t.id=c.id and t.car_datetime>='2012-01-01 00:00:00' 
and t.car_datetime<='2013-01-16 23:59:59' 
and t.id in ( 1013 ) order by carnumber desc";

$m=mysql_query($sql,$connection1);
$_SESSION['mrs']=array();
$sl=mysql_num_rows($m);
if($sl>0){
	$ngu=0;
	while($r=mysql_fetch_array($m)){
		$ob= new sort();
		$ob->newsort($r['id'], $r['name'], $r['car_datetime'], $r['carnumber'], $r['filename'], $r['host'], $r['isReg']);
		$_SESSION['mrs'][$ngu++]=$ob;
	}
}

mysql_close($connection1);
?>
<body style="height:100%" >
	<div id="show">
		<table border="1">
			<tr>
				<td style="cursor: pointer" onclick="sordiem('id')">id</td>
				<td style="cursor: pointer" onclick="sordiem('name')">name</td>
				<td style="cursor: pointer" onclick="sordiem('datetime')">datetime</td>
				<td style="cursor: pointer" onclick="sordiem('carnumber')">carnum</td>
				<td>filename</td>
				<td>host</td>
				<td>reg</td>
			</tr>
			<?php 
				if($sl>0){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize ($_SESSION['mrs'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
				}
			?>
		</table>
	</div>
</body>
</html>